package com.inifitness.message.context;

import java.util.List;
import java.util.Map;

import com.inifitness.common.event.event.MessageEvent;
import com.inifitness.message.processor.message.MessageProcessor;
import com.inifitness.message.service.Achievement;
import com.inifitness.message.service.AchievementService;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * 成就检测上下文
 *
 * @author sunjinfeng
 * @version 1.0.0
 * @since 2024-05-30 16:08
 */
@Component
@RequiredArgsConstructor
@Log4j2
public class AchievementDetectorContext {

  private final AchievementService achievementService;
  private final Map<String, MessageProcessor> senderMap;

  @SuppressWarnings("unused")
  public void detectAchievements(MessageEvent event) {
    List<Achievement> achievements = achievementService.getAllUnlockedAchievements();

    for (Achievement achievement : achievements) {
      boolean achieved = checkCriteria(event, achievement);
      if (achieved) {
        achievementService.unlockAchievement();
      }
    }
  }

  private boolean checkCriteria(MessageEvent event, Achievement achievement) {

    // 检查玩家是否满足成就的条件
    // 示例：if (criteria.equals("score>1000") && player.getScore() > 1000) { return true; }
    // 具体实现根据实际条件编写
    log.debug("事件：{}",event);
    log.debug("成就：{}",achievement);
    return false;
  }
}
